import sys
import pygame
import screen
import menu_screen

class TitleScreen(screen.Screen):
    def __init__(self):
        self.font = pygame.font.Font(None, 18)
        self.font_title = pygame.font.Font("../res/fonts/finalf.ttf",72)
        self.title_screen = pygame.display.set_mode((self.WIDTH, self.HEIGHT), pygame.DOUBLEBUF|pygame.HWSURFACE)
        self.title = self.font_title.render("Red Skies".upper(), True,(255,255,255))
        self.title.set_colorkey(self.title.get_at((self.title.get_width()-1,0)))
        self.title_rect = self.title.get_rect()
        self.title_x = self.WIDTH
        self.width = self.title_screen.get_width()
        self.height = self.title_screen.get_height()
        self.interval = 0.001

        

        self.time = 0.0;
    
    def render(self):
        self.title_screen.fill((12, 72, 75))
        
        if not int(self.time) % 2:
            surf = self.font.render(" - press enter - ", True, (255, 255, 255))
            self.title_screen.blit(surf, (self.WIDTH/2 - 30, self.HEIGHT/2))
            
        self.title_screen.blit(self.title,(self.title_x, 50))
            
    def update(self, time):
        self.time += time
        if self.title_x > 50:
            self.title_x -= 1

    def process_events(self, change_state):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    pygame.quit()
                    sys.exit()
                elif event.key == pygame.K_RETURN:
                    change_state(menu_screen.MenuScreen())
